# eric7.Plugins.CheckerPlugins.CodeStyleChecker.Complexity.ComplexityChecker

Module implementing a checker for code complexity.

### Global Attributes

None

### Classes

ComplexityChecker | Class implementing a checker for code complexity.
LineComplexityVisitor | Class calculating the number of AST nodes per line of code and the median nodes/line score.

### Functions

None

## ComplexityChecker

Class implementing a checker for code complexity.

### Derived from

CodeStyleTopicChecker

### Class Attributes

Category
Codes

### Class Methods

None

### Methods

ComplexityChecker | Constructor
__checkLineComplexity | Private method to check the complexity of a single line of code and the median line complexity of the source code.
__checkMcCabeComplexity | Private method to check the McCabe code complexity.

### Static Methods

None

#### ComplexityChecker (Constructor)

ComplexityChecker(source, filename, tree, select, ignore, args)

Constructor

source (list of str)
  source code to be checked
filename (str)
  name of the source file
tree (ast.Module)
  AST tree of the source code
select (list of str)
  list of selected codes
ignore (list of str)
  list of codes to be ignored
args (dict)
  dictionary of arguments for the miscellaneous checks

#### ComplexityChecker.__checkLineComplexity

__checkLineComplexity()

Private method to check the complexity of a single line of code and the median line complexity of the source code.

Complexity is defined as the number of AST nodes produced by a line of code.

#### ComplexityChecker.__checkMcCabeComplexity

__checkMcCabeComplexity()

Private method to check the McCabe code complexity.

Up

## LineComplexityVisitor

Class calculating the number of AST nodes per line of code and the median nodes/line score.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

LineComplexityVisitor | Constructor
score | Public method to calculate the median.
sortedList | Public method to get a sorted list of (line, nodes) tuples.
visit | Public method to recursively visit all the nodes and add up the instructions.

### Static Methods

None

#### LineComplexityVisitor (Constructor)

LineComplexityVisitor()

Constructor

#### LineComplexityVisitor.score

score()

Public method to calculate the median.

Return:
  median line complexity value

Return Type:
  float

#### LineComplexityVisitor.sortedList

sortedList()

Public method to get a sorted list of (line, nodes) tuples.

Return:
  sorted list of (line, nodes) tuples

Return Type:
  list of tuple of (int,int)

#### LineComplexityVisitor.visit

visit(node)

Public method to recursively visit all the nodes and add up the instructions.

node (ast.AST)
  reference to the node

Up